
/**
 * 统一的音效管理器
 */
export default class Music {
  static instance = null;

  static getInstance() {
    if (!Music.instance) {
      Music.instance = new Music();
    }
    return Music.instance;
  }

  constructor() {
    if (Music.instance) {
      return Music.instance;
    }
    Music.instance = this;
  this.shootAudio = wx.createInnerAudioContext();
  this.shandian = wx.createInnerAudioContext();
    this.shandian.volume = 0.5;

  this.shootAudio.src = 'bgm/shoot.ogg';
  this.shandian.src = 'bgm/shandian.mp3';

    this.initBGM(); // 初始化背景音乐
  }

  initBGM() {
    const innerAudioContext = wx.createInnerAudioContext()
    innerAudioContext.autoplay = true
    innerAudioContext.loop=true
    innerAudioContext.src = 'bgm/bowling.mp3'
    innerAudioContext.volume = 0.5;
    innerAudioContext.onPlay(() => {
      console.log('开始播放')
    })
    innerAudioContext.onError((res) => {
      console.log(res.errMsg)
      console.log(res.errCode)
    })
  }

  playShoot() {
    this.shootAudio.currentTime = 0;
    this.shootAudio.play();
  }

  playShandian() {
    this.shandian.currentTime = 0;
    this.shandian.play();
  }
}
